(function($, window, document, undefined) {
  
  var nav = '.news-side-nav-item'

  $(document).on('click', nav, function(e) {
    e.preventDefault()

    var $el = $(e.target)

    if (!$el.is(nav)) {
      $el = $el.parents(nav)
    }

    var index = $el.index(nav)

    $el
      .addClass('active')
      .siblings()
      .removeClass('active')

    $('.news-panel-item')
      .eq(index)
      .addClass('active')
      .siblings()
      .removeClass('active')

  })
  

  // 视图切换
  $(document).on('click', '.news-preivew-type-switch > a', function(e) {
    e.preventDefault()

    var $el = $(e.target)

    if (!$el.is('[data-type]')) {
      $el = $el.parents('[data-type]')
    }

    var index = $el.index('[data-type]')

    $el
      .addClass('active')
      .siblings()
      .removeClass('active')
    
    if ($el.data('type') === 1) {
      $('.news-main').addClass('_list')
    } else {
      $('.news-main').removeClass('_list')
    }

  })

  // 查看新闻详情
  $(document).on('click', '[data-news]', function(e) {
    e.preventDefault()

    var $detail = $(e.target).parents('.news-block').find('.news-block-detail')

    if (!$detail.length) {
      return
    }

    layer.open({
      type: 1,
      title: false,
      closeBtn: 0,
      area: ['1000px', 'auto'],
      shadeClose: true,
      content: $detail
    })

  })
  
})(jQuery, window, document)